<?php
/**
 * [YIZHIKEJI System] Copyright (c) 2014 yz929.cn
 * YIZHIKEJI is NOT a free software, it under the license terms, visited http://www.yz929.cn/ for more details.
 */
defined('IN_IA') or exit('Access Denied');
$do = in_array($do, array('design', 'page', 'quickmenu', 'article', 'del')) ? $do : 'page';
$multiid = intval($_GPC['multiid']);
define('FRAME', 'weizhan');
$multi = pdo_fetch('SELECT * FROM ' . tablename('site_multi') . ' WHERE uid = :uid AND id = :id', array(':uid' => $_W['uid'], ':id' => $multiid));
if(empty($multi)){
    message('微站不存在或已删除', referer(), 'error');
}
if ($do == "page") {
    // 获取已启用模板
    $sql = "select m.mid,m.title,m.version,m.price, um.deadline as dtime from " . tablename('modules') . " m JOIN (SELECT * from " . tablename('users_modules') . " where uid=" . $_W['uid'] . ") um on m.mid=um.mid";
    $modules = pdo_fetchall($sql);
    // 当前站点
    // 跳转页面
} else if ($do == "quickmenu") {
    $_W['page']['title'] = '快捷菜单 - 站点管理 - 微站功能';
    $type = intval($_GPC['type']) ? intval($_GPC['type']) : 2;
    if ($_GPC['wapeditor']) {
        $params = $_GPC['wapeditor']['params'];
        if (empty($params)) {
            message('请您先设计手机端页面.', '', 'error');
        }
        $params = json_decode(html_entity_decode(urldecode($params)), true);
        if (empty($params)) {
            message('请您先设计手机端页面.', '', 'error');
        }
        $html = htmlspecialchars_decode($_GPC['wapeditor']['html'], ENT_QUOTES);
        $data = array(
            'uid' => $_W['uid'],
            'multiid' => $multiid,
            'title' => '底部菜单',
            'description' => '',
            'status' => intval($_GPC['status']),
            'type' => $type,
            'params' => json_encode($params),
            'html' => $html,
            'createtime' => TIMESTAMP,
        );
        if ($type == '4') {
            $id = pdo_fetchcolumn("SELECT id FROM ".tablename('site_page')." WHERE uid = :uid AND type = :type", array(':uid' => $_W['uid'], ':type' => $type));
        } else {
            $id = pdo_fetchcolumn("SELECT id FROM ".tablename('site_page')." WHERE multiid = :multiid AND type = :type", array(':multiid' => $multiid, ':type' => $type));
        }
        if (!empty($id)) {
            pdo_update('site_page', $data, array('id' => $id));
        } else {
            pdo_insert('site_page', $data);
            $id = pdo_insertid();
        }
        message('底部菜单保存成功.', url('weizhan/editor/quickmenu', array('multiid' => $multiid, 'type' => $type)), 'success');
    }
    if ($type == '4') {
        $page = pdo_fetch("SELECT * FROM ".tablename('site_page')." WHERE type = :type AND uid = :uid", array(':type' => $type, ':uid' => $_W['uid']));
    } else {
        $page = pdo_fetch("SELECT * FROM ".tablename('site_page')." WHERE multiid = :multiid AND type = :type", array(':multiid' => $multiid, ':type' => $type));
    }
    $modules = uni_modules();
}
template('weizhan/index');

